//
//  LoginClassAPI.swift
//  DKE-Album
//
//  Created by 杨东宝 on 2020/5/18.
//  Copyright © 2020 杨东宝. All rights reserved.
//

import UIKit
import Moya
import KakaJSON

// 请求分类
public enum UserClassAPI {
    
    case loginToServerCode(_ dict:[String:Any]) //手机验证码登录
    case getCodeToServer(_ phone:String) //获取验证码 注册登录时候
    
    case loginToServerPwd(_ dict:[String:Any])  //手机密码登录
    
    case changePassword(_ dict:[String:Any]) //修改登录密码
    case getCodeTochangePssword(_ phone:String) //获取验证码 修改登录密码
    
    case loginThirdQQ(_ dict:[String:Any]) //第三方登录 QQ
    case loginThirdWebChet(_ dict:[String:Any]) //第三方登录 微信
    
    case getCodeToBindThirdPhone(_ phone:String) //获取验证码 微信QQ绑定手机
    case bandingThirdPhone(_ dict:[String:Any]) //微信QQ绑定手机号
    
    
    case getCodeToBindPhone(_ phone:String) //获取验证码修改绑定手机号
    case bandingPhoneToServer(_ dict:[String:Any]) //绑定手机号带密码
    case bandingPhone(_ dict:[String:Any]) //修改绑定手机号
    
    case loadUserInfor //获取用户信息
    case loginOut //退出登录
    
}
// 请求配置
extension UserClassAPI: TargetType {
    
    // 各个请求的具体路径
    public var path: String {
        switch self {
        case .loginToServerCode:return "/vistor/reg"
        case .loginToServerPwd:return "/vistor/login"
        case .changePassword:return "/vistor/resetPass"
        case .loginThirdQQ:return "/vistor/qq"
        case .loginThirdWebChet:return "/vistor/wx"
            
        case .getCodeToBindThirdPhone: return "/vistor/sendSmsOfThird"
        case .bandingThirdPhone:return "/vistor/thirdPartyReg"
            
        case .bandingPhoneToServer:return "/user/bindPhonePass"
        case .bandingPhone:return "/user/bindPhone"
        case .loadUserInfor:return "/user/info"
        case .loginOut:return "/home/new/index"
        case .getCodeToServer:return "/vistor/sendSmsOfReg"
        case .getCodeTochangePssword: return "/vistor/sendSmsOfReset"
        case .getCodeToBindPhone: return "/user/sendSmsOfBind"
        }
    }
    // 请求类型
    public var method: Moya.Method {
        switch self {
        case .loginToServerCode:
            return .post
        case .loginToServerPwd:
            return .post
        case .changePassword:
            return .post
        case .loginThirdQQ:
            return .post
        case .loginThirdWebChet:
            return .post
        case .bandingPhoneToServer:
            return .post
        case .bandingPhone:
            return .post
        case .loginOut:
            return .post
        case .getCodeToServer:
            return .post
        case .getCodeTochangePssword:
            return .post
        case .getCodeToBindPhone:
            return .post
        case .getCodeToBindThirdPhone:
            return .post
        case .bandingThirdPhone:
            return .post
        case .loadUserInfor:return .post
        }
    }
    
    // 请求任务事件（这里附带上参数）
    public var task: Task {
        
        switch self {
        case .loginToServerCode(dict:let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .loginToServerPwd(dict:let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .changePassword(dict: let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .loginThirdQQ(dict: let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .loginThirdWebChet(dict: let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .bandingPhoneToServer(dict: let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .bandingPhone(dict: let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .loadUserInfor:
            return .requestPlain
        case .bandingThirdPhone(dict: let dict):
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
        case .loginOut:
            return .requestPlain
        case .getCodeToServer(phone:let phone):
            do {
                let dict = ["phone":phone]
                return .requestParameters(parameters: dict, encoding: URLEncoding.default)
            }
            
        case .getCodeTochangePssword(phone:let phone):do {
            let dict = ["phone":phone]
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
            }
            
        case .getCodeToBindPhone(phone:let phone):do {
          
            let dict = ["phone":phone]
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
            }
        case .getCodeToBindThirdPhone(phone:let phone):do {
        
            let dict = ["phone":phone]
            return .requestParameters(parameters: dict, encoding: URLEncoding.default)
            }
            
        }
    }
}
// 是否执行Alamofire验证
public var validate: Bool {
    return false
}



